<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>扫码</title>
		<link rel="stylesheet" href="../css/common.css" />
		<style>
			.mask {
				height: 100%;
				width: 100%;
				position: absolute;
				top: 0;
				background: #ffffff;
			}
		</style>
	</head>

	<body>
		<div class="mask" id="mask">

		</div>
		<script src="../config.js"></script>
		<script src="../js/mui.min.js"></script>
		<script type="text/javascript">
			mui.init()
			var scan;
			var userInfo = {}
			var currentShopObj
			var extra
			var type
			var classInfo
			var programmeInfo
			var checkedProData
			var storeId
			var originData
			if(window.plus) {
				plusready();
			} else {
				document.addEventListener('plusready', plusready, false);
			}

			function plusready() {
				receiveParams()
				setTimeout(function() {
					scan = new plus.barcode.Barcode('mask');
					scan.start();
					scan.onmarked = function(type, result) {
						if(result) {
							scan.close();
							//strA[0] === '4'  首页扫码 核对奖品
              var strA = result.split('t=')[1].split('&d=')
							console.log(JSON.stringify(strA))
							if(strA[0] === '1') { //会员中心ID
								config.ajax({
									url: '/redemption/checkVip',
									data: {
										userId: 2 * 100000000 + strA[1] * 1
									},
									success: function(res) {
										if(res.result === 1) {
											userInfo.point = res.point
											userInfo.userName = res.userName
											userInfo.userId = 2 * 100000000 + res.userId * 1
											userInfo.header = res.header
											userInfo.openId = res.openId
											next()
										} else {
											mui.toast(res.errormsg)
											setTimeout(function() {
												//       	var wn = plus.webview.getLaunchWebview(); //传递消息返回的webview
												plus.webview.currentWebview().close();
											}, 200)
										}
									}
								})
							} else if(strA[0] === '2') {
								config.ajax({
									url: '/scanf/parseTicket.do',
									data: {
										data: strA[1]
									},
									success: function(res) {
										if(res.result === 1) {
												extra = {
													res: res,
													currentShopObj: currentShopObj
												}
												next()
										} else {
											mui.toast(res.errormsg)
											setTimeout(function() {
												//       	var wn = plus.webview.getLaunchWebview(); //传递消息返回的webview
												plus.webview.currentWebview().close();
											}, 200)
										}
									}
								})
							} else if(strA[0] === '3') {
								config.ajax({
									url:'/live/getInfo',
									data:{
										data:strA[1]
									},
									success:function(res){
										if(res.result ===1) {
											 extra = {
												currentShopObj: currentShopObj,
												res: res.userdata,
												data:strA[1],
												type:4
											}
											next(4)
										} else {
											mui.toast(res.errormsg)
											setTimeout(function() {
												//       	var wn = plus.webview.getLaunchWebview(); //传递消息返回的webview
												plus.webview.currentWebview().close();
											}, 200)
										}
									}
								})
							}else if(strA[0] === '4'){
                config.ajax({
                  url:'/voucher/getGoodsVoucher',
                  data:{
                    data:strA[1],
                    storeId:storeId
                  },
                  success:function(res){
                    if(res.result ===1) {
                      res.voucher.data=strA[1]
                      extra = {
                        res: res.voucher,
                        originData:originData
                      }
                      localStorage.setItem('isShow',1)
											console.log(JSON.stringify(extra))
                      next(8)
                    } else {
                      mui.toast(res.errormsg)
                      setTimeout(function() {
                        plus.webview.currentWebview().close();
                      }, 200)
                    }
                  }
                })
							}else if(strA[0] === '5'){

                config.ajax({
                  url:'/collect/writeOffMedalGoods',
                  data:{
                    data:strA[1],
                  },
                  success:function(res){
                    if(res.result ===1) {
                      plus.webview.currentWebview().close();
                      window.sessionStorage.setItem('imgUrl',res.medalIcon)
                      var index= plus.webview.getWebviewById('index')
                      mui.fire(index,'change',{
                        url:res.medalIcon
                      });

                    } else {
                      mui.confirm(res.errormsg, '提示', ['确定'], function(e) {

                      })
                      setTimeout(function() {
                        plus.webview.currentWebview().close();
                      }, 200)
                    }
                  }
                })
							}
						}
					};
				}, 200)
				//处理返回事件
				plus.key.addEventListener('backbutton', function() {
          plus.webview.currentWebview().hide();
					plus.webview.currentWebview().close();
				})
			}

			function receiveParams() {
				var self = plus.webview.currentWebview()
				currentShopObj = self.currentShopObj
        originData = self.originData ?  self.originData :''

				type = self.type
				if(type === 6){
          classInfo=self.classInfo
          programmeInfo=self.programmeInfo
          checkedProData=self.checkedProData
				}
				storeId=self.storeId ?  self.storeId : ''
			}

			function next(nType) {
				if(nType) {type = nType}
				if(type === 1) {
					var title = '娃娃兑积分'
					var url = '../integral/recovery-goods.html'
					var id = 'recovery-goods'
					extra = {
						currentShopObj: currentShopObj,
						userInfo: userInfo
					}
				} else if(type === 2) {
					var title = '存彩票'
					var url = '../ticket/storeTicket.html'
					var id = 'storeTicket'
				} else if(type === 3) {
					var title = '兑换礼品'
					var url = '../exchange/exchange.html'
					var id = 'exchange'
					extra = {
						currentShopObj: currentShopObj,
						userInfo: userInfo
					}
				} else if(type === 4) {
					var title = '兑换礼品'
					var url = '../exchange/exchange.html'
					var id = 'exchange'
				}else if(type === 5) {
          var title = '人工清票存积分'
          var url = '../integral/people/people.html'
          var id = 'people'
          extra={
            currentShopObj: currentShopObj,
            userInfo: userInfo
					}
        }else if(type === 6) {
          var title = '卡片存积分'
          var url = '../integral/cardSaveIntegral/addIntegral.html'
          var id = 'addIntegral'
          extra={
            currentShopObj: currentShopObj,
            userInfo: userInfo,
            classInfo: classInfo,
            programmeInfo: programmeInfo,
            checkedProData:checkedProData,
          }
        }else if(type === 7){
          var title = '手动存积分'
          var url = '../integral/handSaveIntegral/handSaveIntegral.html'
          var id = 'handSaveIntegral'
          extra={
            currentShopObj: currentShopObj,
            userInfo: userInfo,
          }
				}else if(type === 8){
          var title = ''
          var url = '../index.html'
          var id = 'index'
        }


				mui.openWindow({
					url: url,
					id: id,
					styles: {
						top: 0, //新页面顶部位置
						bottom: 0, //新页面底部位置         
						titleNView: {
							titleText: title,
							titleColor: "#FFFFFF",
							titleSize: "17px",
							backgroundColor: "#FF6800",
							autoBackButton: true,
							//                homeButton: true,
//							buttons: [{
//								float: "right",
//								fontSize: "18px",
//								fontSrc: "_www/fonts/iconfont.ttf", //wap2app内置字体文件
//								text: "\ue602",
//								onclick: function() {
//									var allPage = plus.webview.all()
//									var nowPage = plus.webview.getWebviewById('index')
//									for(var i = 0; i < allPage.length; i++) {
//										if(allPage[i].getURL() !== nowPage.getURL()) {
//											plus.webview.close(allPage[i]);
//										}
//									}
//								}
//							}],
							splitLine: {
								color: "#CCCCCC",
								height: "1px"
							}
						}
					},
					extras: extra,
          createNew:true
				})
				setTimeout(function() {
					//       	var wn = plus.webview.getLaunchWebview(); //传递消息返回的webview
					plus.webview.currentWebview().hide();
					plus.webview.currentWebview().close();
				}, 400)
			}
		</script>
	</body>

</html>